<?php
    

    include_once 'activitymodel.php';
    
    $page = new pager();
    if(!isset($_GET["aid"])){
        $list_act = get_all_activity($page, "?page=");
    }else if(isset($_GET["aid"]) && !empty($_GET["aid"])){
        $list_act = get_act_by_id($_GET["aid"]);
    }else if(isset($_GET["aid"]) && empty($_GET["aid"])){
        $list_act = get_all_activity($page, "?page=");
    }
        
    $list_act_left = get_act_to_left_bar();
    if($_POST["checksubmit"] == "submittour"){
        $date = date("Y-m-d H:i:s",  strtotime("{$_POST["ngaybatdau"]}"));
        $array = array(
            "id" => "''",
            "user_id" => "{$_COOKIE["id"]}",
            "chude" => "'{$_POST["chude"]}'",
            "ngaybatdau" => "'{$date}'",
            "sotienphaidong" => "'{$_POST["sotienphaidong"]}'",
            "diadiem" => "'{$_POST["diadiem"]}'",
            "image" => "'{$_POST["image"]}'",
            "mieuta" => "'{$_POST["mieuta"]}'"
        );            
        them_moi_activity($array);
        echo "<script>window.location = window.location;</script>";
    }
    if($_POST["checksubmit"] == "updatetour"){
        $date = date("Y-m-d H:i:s",  strtotime("{$_POST["ngaybatdau"]}"));
        $array = array(            
            "user_id" => "{$_COOKIE["id"]}",
            "chude" => "'{$_POST["chude"]}'",
            "ngaybatdau" => "'{$date}'",
            "sotienphaidong" => "'{$_POST["sotienphaidong"]}'",
            "diadiem" => "'{$_POST["diadiem"]}'",
            "image" => "'{$_POST["image"]}'",
            "mieuta" => "'{$_POST["mieuta"]}'"
        );            
        sua_activity($array,$_POST["act_val"]);
        echo "<script>window.location = window.location;</script>";
    }
    if($_GET["action"] == "get_data_tour"){
        echo get_activity_by_id_to_edit($_GET["id"]);
    }
    if($_GET["action"] == "delete_tour"){
        echo xoa_activity($_GET["id"]);
    }
?>
